<?php

//************************************************************************************
$appId = "123456789";
$appName = "myappname";
$appPermissions = "publish_stream,read_stream,user_likes,user_status,user_photos,email";
// !!! in app settings/advanced, set 'OAuth 2.0 for Canvas' to 'enabled' !!!
//************************************************************************************


$url = null;
$mustLogin = false;

$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

if (empty($data["oauth_token"]))
{
	$url = "http://www.facebook.com/dialog/oauth";
	$url .= "?client_id=".$appId;
	$url .= "&redirect_uri=".urlencode("http://apps.facebook.com/".$appName."/");
	$url .= "&scope=" . $appPermissions;
	$mustLogin = true;
}

?>


<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
	<head>
		<title>Project name</title>
		<!-- Meta -->
		<meta name="author" content="Marcel" />
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		
		<!-- CSS -->
		<style type="text/css">
		body { margin:0; padding:0; font-family:arial; font-size:10px }
		</style>
		
		<!-- JS -->
		<script type="text/javascript" src="web/js/swfobject.js"></script>
		<script type="text/javascript" src="web/js/swfaddress.js"></script>
		<script type="text/javascript">
			
			<?php
			
			if ($mustLogin) echo 'window.top.location = "'.$url.'";';
			else
			{
			?>
			
			var flashvars = {};
			flashvars.oauth_token = "<?php echo $data["oauth_token"]; ?>";
			flashvars.c = "fr";
			flashvars.l = "fr";
			flashvars.htmlembed = "true";
			flashvars.site_xml = "web/xml/config/site.xml";
			flashvars.enable_debug = "false";
			if (window.location.hash.length > 0) flashvars.state = window.location.hash.substring(1);
			
			var params = {};
			params.allowscriptaccess  = "always";
			params.allowfullscreen  = "true";
			params.scale = "noscale";
			params.menu = "false";
			params.quality = "high";
			params.bgcolor = "#DDDDDD";
			//params.wmode = "opaque";
			
			var attributes = {};
			attributes.id = "mainswf";
			attributes.name = "mainswf";
	
			swfobject.embedSWF("web/swf/main.swf", "flashcontent", "740", "590", "9.0.115", "web/swf/expressInstall.swf", flashvars, params, attributes);
			
			<?php
			}
			?>
			
			//]]>
        </script>
		
	</head>
	
	<body>
		<div id="content">
			<div id="flashcontent"></div>
		</div>
	</body>
	
</html>